package com.cinema.service.impl;

import com.cinema.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class RedisServiceImpl implements RedisService {
    @Autowired
    RedisTemplate redisTemplate;
    @Override
    public boolean set(String key, Object val) {
        try {
            redisTemplate.opsForValue().set(key, val);
        }catch (Exception e) {
            return false;
        }
        return true;
    }

    @Override
    public Object get(String key) {
        return redisTemplate.opsForValue().get(key);
    }

    @Override
    public boolean del(String key) {
        return redisTemplate.delete(key);

    }
    public void setex(String key,int second,Object val){
        redisTemplate.opsForValue().set(key,val,second, TimeUnit.SECONDS);
    }


}

















